using Godot;
using System;

namespace Box;

public static class PropertyHelper {
    public static PropertyType StringTypeToPropertyType(string name) {
        switch(name) {
            case "number" : return PropertyType.Number;
            case "boolean" : return PropertyType.Boolean;
            case "string" : return PropertyType.String;
            case "code" : return PropertyType.Code;
            case "task" : return PropertyType.Task;
            case "action" : return PropertyType.Action;
        }

        return PropertyType.String;
    }

    public static Node CreatePropertyControl(PropertyType type,string name) {
        Node node = null;
        switch(type) {
            case PropertyType.Number : {
                node = GD.Load<PackedScene>("res://source/process_tree_editor/property_control/number_property_control/NumberPropertyControl.tscn").Instantiate<Node>();
            }break;
            case PropertyType.Boolean : {
                node = GD.Load<PackedScene>("res://source/process_tree_editor/property_control/boolean_property_control/BooleanPropertyControl.tscn").Instantiate<Node>();
            }break;
            case PropertyType.String : {
                node = GD.Load<PackedScene>("res://source/process_tree_editor/property_control/string_property_control/StringPropertyControl.tscn").Instantiate<Node>();
            }break;
            case PropertyType.Code : {
                node = GD.Load<PackedScene>("res://source/process_tree_editor/property_control/code_property_control/CodePropertyControl.tscn").Instantiate<Node>();
            }break;
            case PropertyType.Task : {
                node = GD.Load<PackedScene>("res://source/process_tree_editor/property_control/task_select_property_control/TaskSelectPropertyControl.tscn").Instantiate<Node>();
            }break;
            case PropertyType.Action : {
                node = GD.Load<PackedScene>("res://source/process_tree_editor/property_control/action_select_property_control/ActionSelectPropertyControl.tscn").Instantiate<Node>();
            }break;
        }

        IProperty property = node as IProperty;
        property.PName = name;
        return node;
    }
}